package projectsupporter.common.formbase.progrees;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class LongRunningOperation extends Thread {
	protected Display display;
	protected ProgressBarDialog progressBar;

	public LongRunningOperation(Shell shell) {
		this.display = shell.getDisplay();
		this.progressBar = new ProgressBarDialog(shell);
	}

	protected void move(final int value,final String detialInfo ) {
		display.asyncExec(new Runnable() {
			public void run() {
				
				if(detialInfo!=null)
				{
					progressBar.setDetialInfo(detialInfo);
				}
				
				if (!progressBar.getProgressBar().isDisposed())
				{
					// 进度条递增
					progressBar.getProgressBar().setSelection(value);
					//progressBar.setValue(value);
					//System.out.println("-------------------"+value);
				}
				
			}
		});
	}
	
	public void setMax(final int max)
	{
		display.asyncExec(new Runnable() {
			public void run() {
				progressBar.setMax(max);
				progressBar.open();
			}
		});
		
	}
	
	public void setMin(final int min)
	{
		display.asyncExec(new Runnable() {
			public void run() {
				progressBar.setMin(min);
			}
		});	
	}
	
	public void setActionName(final String actionName)
	{
		display.asyncExec(new Runnable() {
			public void run() {
				progressBar.setActionName(actionName);
			}
		});	
		
	}
	
	public void setDetialName(final String detialName)
	{
		display.asyncExec(new Runnable() {
			public void run() {
				progressBar.setDetialName(detialName);
			}
		});	
		
	}
	
	public void setDetialInfo(final String detialInfo)
	{
		display.asyncExec(new Runnable() {
			public void run() {
				progressBar.setDetialInfo(detialInfo);
			}
		});	
		
		
	}

}
